#' @export
make_descriptive_tables <- function() {

box::use(
    ./helpers/theme_helpers[conjoint_reshape, plexi, format_si, percent],
    dplyr[...],
    data.table[setDT],
    here[here],
    tibble[add_column],
    vtable[st],
    qpcR,
    xtable[xtable],
    likert[...],
    ggplot2[...]
)


df_clean <- readRDS(here("data/df_ordering.RDS"))

lik <- df_clean %>% 
  select(Q16r1, Q16r2, Q16r4) 

names(lik) <- c(
  Q16r1 ="I often did not know what to answer.",
  Q16r2 ="It was easy to make a decision between the requests for arms exports.",
  Q16r4 ="I was missing important information in the tables to make a proper decision.")

lik <- likert(lik) 

p <- plot(lik, plot.percents = T, centered = T) + plexi() +
  scale_fill_manual(values = c("#d73027", "#dc7767","#f5b294","#d8d4d4","#A2CDE3","#5EA3CB","#417CB8"),
                    labels = c("(1)",
                               "(2)", 
                               "(3)",
                               "(4)",  
                               "(5)",  
                               "(6)", 
                               "(7)")) +
  theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), 
        legend.position = "bottom", legend.title=element_blank(), legend.title.align = 0) + 
  guides(fill=guide_legend(label.position = "bottom", nrow = 1, override.aes = list(size = 1))) +
  theme(text = element_text(size=20), legend.text=element_text(size=20))
p

ggsave(filename = here("figures/fig_5.pdf"), width = 11.5, height = 5, device = cairo_pdf)

pdf_convert("figures/fig_5.pdf", filenames = "figures/fig_5.tiff", dpi = 300, format = "tiff")
# ------------------------------ appendix tables ----------------------------- #

des1 <- df_clean %>% 
  filter(hCountry == "Germany") %>% 
  st(., vars = c("Education", "Age", "Gender"), out = "return", digits = 3) %>% 
  add_column(Target = c(NA, 0.195,
                        0.545,
                        0.259,
                        NA,
                        0.104,
                        0.176,
                        0.170,
                        0.200,
                        0.207,
                        0.142,
                        NA,
                        0.498,
                        0.502,
                        NA
                        )) 
 
des1$Target <- percent(des1$Target) 
setDT(des1)
des1 <- des1[Target == "NA%", Target := NA]
                       

des2 <- df_clean %>%
  filter(hCountry == "France") %>% 
  st(., vars = c("Education", "Age", "Gender"), out = "return", digits = 3)  %>% 
  add_column(Target = c(NA, 0.234,
                        0.429,
                        0.337,
                        NA,
                        0.117,
                        0.168,
                        0.179,
                        0.193,
                        0.183,
                        0.161,
                        NA,
                        0.488,
                        0.512,
                        NA
  )) 

des2$Target <- percent(des2$Target) 
setDT(des2)
des2 <- des2[Target == "NA%", Target := NA]

des2 <- select(des2, -c("Variable"))

des_comb <- qpcR:::cbind.na(des1, des2)

print(xtable(des_comb, align = "llrrrrrr"), include.rownames=FALSE, file= here("tabs/table_a_7.tex"))


r1 <- df_clean %>% 
  filter(hCountry == "Germany") %>% 
  st(., vars = c("region_de"), out = "return", digits = 3) %>% 
  add_column(Target = c(NA, 0.133,
                        0.158,
                        0.044,
                        0.030,
                        0.008,
                        0.022,
                        0.076,
                        0.019,
                        0.096,
                        0.216,
                        0.049,
                        0.012,
                        0.049,
                        0.026,
                        0.035,
                        0.026)) 

r1$Target <- percent(r1$Target) 
setDT(r1)
r1 <- r1[Target == "NA%", Target := NA]


r2 <- df_clean %>% 
  filter(hCountry == "France") %>% 
  st(., vars = c("region_fr"), out = "return", digits = 3) %>% 
  add_column(Target = c(NA, 0.124,
                        0.043,
                        0.051,
                        0.039,
                        0.005,
                        0.085,
                        0.092,
                        0.189,
                        0.051,
                        0.092,
                        0.091,
                        0.059,
                        0.078
  )) 


r2$Target <- percent(r2$Target) 
setDT(r2)
r2 <- r2[Target == "NA%", Target := NA]


r_comb <- qpcR:::cbind.na(r1, r2)

print(xtable(r_comb, align = "llrrrlrrr"), include.rownames=FALSE, , file= here("tabs/table_a_8.tex"))


add1 <- df_clean %>% 
  filter(hCountry == "Germany") %>% 
  st(., vars = c("Household_Size", "Household_Income", "Job_situation", "Econ_self", "Econ_country",
                 "Pol_Interest", "lr", "party_choice_de"), out = "return", summ = c('notNA(x)','mean(x)','sd(x)')) 

add2 <- df_clean %>% 
  filter(hCountry == "France") %>% 
  st(., vars = c("Household_Size", "Household_Income", "Job_situation", "Econ_self", "Econ_country", 
                 "Pol_Interest", "lr", "party_choice_fr"), out = "return", summ = c('notNA(x)','mean(x)','sd(x)')) 

add_comb <- qpcR:::cbind.na(add1, add2)

print(xtable(add_comb, align = "llrrrlrrr"), include.rownames=FALSE, file= here("tabs/table_a_9.tex"))


}